package com.igroupes.ovineherd.config;

import com.igroupes.ovineherd.file.core.FileStore;
import com.igroupes.ovineherd.file.core.FileStoreFactory;
import com.igroupes.ovineherd.file.core.SimpleFileStoreConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FileStoreConfig {
    @Autowired
    private FileStoreProperties storeProperties;

    @Bean
    public FileStore fileStore(){
        SimpleFileStoreConfig simpleFileStoreConfig = new SimpleFileStoreConfig();
        simpleFileStoreConfig.setDownloadUrlPrefix(storeProperties.getDownloadUrlPrefix());
        simpleFileStoreConfig.setFileStoreDir(storeProperties.getFileStoreDir());
        simpleFileStoreConfig.setStoreDirMaxBytes(storeProperties.getStoreDirMaxBytes());
        return FileStoreFactory.instance().fileStore(storeProperties.getType(),simpleFileStoreConfig);
    }

}
